#!/bin/csh -f
if(! -f mktm.def) then
    echo "File mktm.def must be present in the curdir"
    exit
endif
set rn=`awk '$1=="rootname"{print $2}' mktm.def`
set ti=`awk '$1=="tilings"{print $2}' mktm.def`
set erep=`awk '$1=="erep"{print $2}' mktm.def`
set mdir=`pwd`
set tind=`awk '{print $1}' $rn.ldef`
@ j =0
echo "reorganizing dir tree ( $#tind layers) : "
foreach i ($tind)
    @ j++
    echo -n $j" "
    if(! -d "L"$j) mkdir "L"$j
#    echo ddd
#    exit
    if(-f $rn""x2_$j.2nd) mv $rn""x2_$j.2nd "L"$j/2nd
    if(-f $rn""x2_$j.2nd.erep) mv $rn""x2_$j.2nd.erep "L"$j/2nd.erep
    if(-f $rn""x2_$j.2nd.edat) mv $rn""x2_$j.2nd.edat "L"$j/2nd.edat
    if(-f $rn""x2_$j.two) mv $rn""x2_$j.two "L"$j/two
    if(-f $rn""x2_$j.two.erep) mv $rn""x2_$j.two.erep "L"$j/two.erep
    if(-f $rn""x2_$j.two.edat) mv $rn""x2_$j.two.edat "L"$j/two.edat
    if(-f $rn""x2_$j.tsta) mv $rn""x2_$j.tsta "L"$j/tsta
    if(-f $rn""x2_$j.sort) mv $rn""x2_$j.sort "L"$j/sort
    cd "L"$j
    if(-f two) gzip two 
    if(-f 2nd) gzip 2nd 
    if(-f sort) gzip sort
    cd ../
end
echo done
##
